package com.mx.tool.form.factory;

import com.intellij.ui.JBColor;
import com.mx.tool.form.window.jy.CronWindow;
import com.mx.tool.form.window.jy.ZzWindow;
import com.mx.tool.form.window.website.CommonWindow;
import com.mx.tool.form.window.website.FrontWindow;
import com.mx.tool.form.window.website.FwqWindow;
import com.mx.tool.form.window.website.KjWindow;

import javax.swing.*;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 08:51
 * @Description:
 */
public class WebsiteFactory {

    private final static CommonWindow COMMON_WINDOW;
    private final static FwqWindow FWQ_WINDOW;
    private final static KjWindow KJ_WINDOW;
    private final static FrontWindow FRONT_WINDOW;

    static {
        COMMON_WINDOW = new CommonWindow();
        FWQ_WINDOW = new FwqWindow();
        KJ_WINDOW = new KjWindow();
        FRONT_WINDOW = new FrontWindow();
    }


    /**
     * 添加监听
     * @param commonButton
     * @param fwqButton
     * @param kjButton
     * @param websitePanel
     */
    public static void addActionListeners(JButton commonButton, JButton fwqButton,JButton kjButton,JButton frontButton,JPanel websitePanel) {
        JPanel commonJPanel = COMMON_WINDOW.getContent();
        JPanel fwqJPanel = FWQ_WINDOW.getContent();
        JPanel kjJPanel = KJ_WINDOW.getContent();
        JPanel frontJPanel = FRONT_WINDOW.getContent();
        websitePanel.add("commonJPanel", commonJPanel);
        websitePanel.add("fwqJPanel", fwqJPanel);
        websitePanel.add("kjJPanel", kjJPanel);
        websitePanel.add("frontButton", frontJPanel);
        commonButton.setForeground(JBColor.GREEN);
        commonButton(commonButton,fwqButton,kjButton,frontButton,commonJPanel,fwqJPanel,kjJPanel,frontJPanel);
        fwqButton(commonButton,fwqButton,kjButton,frontButton,commonJPanel,fwqJPanel,kjJPanel,frontJPanel);
        kjButton(commonButton,fwqButton,kjButton,frontButton,commonJPanel,fwqJPanel,kjJPanel,frontJPanel);
        frontButton(commonButton,fwqButton,kjButton,frontButton,commonJPanel,fwqJPanel,kjJPanel,frontJPanel);
    }

    private static void commonButton(JButton commonButton, JButton fwqButton,JButton kjButton,JButton frontButton,
                                     JPanel commonJPanel, JPanel fwqJPanel,JPanel kjJPanel,JPanel frontJPanel) {
        commonButton.addActionListener(e -> {
            fwqJPanel.setVisible(false);
            fwqButton.setForeground(JBColor.BLACK);
            kjJPanel.setVisible(false);
            kjButton.setForeground(JBColor.BLACK);
            frontJPanel.setVisible(false);
            frontButton.setForeground(JBColor.BLACK);
            commonJPanel.setVisible(true);
            commonButton.setForeground(JBColor.GREEN);
        });
    }

    private static void fwqButton(JButton commonButton, JButton fwqButton,JButton kjButton,JButton frontButton,
                                     JPanel commonJPanel, JPanel fwqJPanel,JPanel kjJPanel,JPanel frontJPanel) {
        fwqButton.addActionListener(e -> {
            commonJPanel.setVisible(false);
            commonButton.setForeground(JBColor.BLACK);
            kjJPanel.setVisible(false);
            kjButton.setForeground(JBColor.BLACK);
            frontJPanel.setVisible(false);
            frontButton.setForeground(JBColor.BLACK);
            fwqJPanel.setVisible(true);
            fwqButton.setForeground(JBColor.GREEN);
        });
    }

    private static void kjButton(JButton commonButton, JButton fwqButton,JButton kjButton,JButton frontButton,
                                  JPanel commonJPanel, JPanel fwqJPanel,JPanel kjJPanel,JPanel frontJPanel) {
        kjButton.addActionListener(e -> {
            commonJPanel.setVisible(false);
            commonButton.setForeground(JBColor.BLACK);
            fwqJPanel.setVisible(false);
            fwqButton.setForeground(JBColor.BLACK);
            frontJPanel.setVisible(false);
            frontButton.setForeground(JBColor.BLACK);
            kjJPanel.setVisible(true);
            kjButton.setForeground(JBColor.GREEN);
        });
    }

    private static void frontButton(JButton commonButton, JButton fwqButton,JButton kjButton,JButton frontButton,
                                 JPanel commonJPanel, JPanel fwqJPanel,JPanel kjJPanel,JPanel frontJPanel) {
        frontButton.addActionListener(e -> {
            commonJPanel.setVisible(false);
            commonButton.setForeground(JBColor.BLACK);
            fwqJPanel.setVisible(false);
            fwqButton.setForeground(JBColor.BLACK);
            kjJPanel.setVisible(false);
            kjButton.setForeground(JBColor.BLACK);
            frontJPanel.setVisible(true);
            frontButton.setForeground(JBColor.GREEN);
        });
    }


}
